package com.laoyao.controller;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.laoyao.beans.PageBean;
import com.laoyao.comm.config.CrossOrigin;
import com.laoyao.service.CommentService;
import com.laoyao.service.UserService;
import com.laoyao.service.VideoService;

@CrossOrigin
public class AdminController extends Controller {
	// 考虑到此控制类可能会过大，所以所有的业务逻辑基本会放到service层
	// 用户列表
	public void userList() {
		PageBean p = getBean(PageBean.class, "");
		String userName = getPara();
		renderJson("page", UserService.me.userList(p.getPageNumber(),
				p.getPageSize(), userName));
	}

	// 修改用户状态
	public void userState() {
		String state = getPara("state");
		String id = getPara("id");
		renderJson("success", UserService.me.setState(id, state));
	}

	// 评论列表
	public void commentList() {
		PageBean p = getBean(PageBean.class, "");
		String userName = getPara("userName");
		String title = getPara("title");
		renderJson("page", CommentService.me.list(p.getPageNumber(),
				p.getPageSize(), userName, title));
	}

	// 修改评论状态
	public void commentState() {
		Integer id = getParaToInt("id");
		Integer state = getParaToInt("state");
		renderJson("success", CommentService.me.setState(id, state));
	}

	// 返回视频列表
	public void videoList() {
		PageBean p = getBean(PageBean.class, "");
		String title = getPara("title");

		renderJson("page", VideoService.me.list(p.getPageNumber(),
				p.getPageSize(), title, "", "", ""));
	}

	public void videoState() {
		String state = getPara("state");
		String id = getPara("id");
		String sql = "update v_video set state=? where id=?";
		renderJson("success", Db.update(sql, state, id));
	}

	// 视频审核状态
	public void videoCheckState() {
		String state = getPara("state");
		String id = getPara("id");
		String sql = "update v_video set checkState=? where id=?";
		renderJson("success", Db.update(sql, state, id));
	}

}
